﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Configuration;
using System.Data;

namespace LineWatchSimple.WinForm
{
    public static class ConfigInfo
    {
        public static bool IsUseCustomizedFont = true;
        public static float FontSizeTitle = 40;
        public static float FontSizeCaption = 50;
        public static float FontSizeValue = 60;
        public static float FontSizeScreenSaver = 70;

        public static bool IsProductPC = true;
        public static string WatchLines = string.Empty;

        public static bool IsUseScreenSaver = true;
        public static int ShowScreenSaverSpan = 300000;
        public static int RefreshSaverSpan = 8000;

        public static bool IsDemoTimerEnable = true;
        public static int UpdateDemoProductInfoSpan = 1000;
        public static int RefreshLineInfoSpan = 1000;
        public static int RefreshProductInfoSpan = 1000;

        public static string LineCode1 = "A";
        public static string LineCode2 = "B";
        public static string LineCode3 = "C";

        public static string LineName1 = "A线";
        public static string LineName2 = "B线";
        public static string LineName3 = "C线";

        public static string ShiftCodeA = "ShiftA";
        public static string ShiftCodeB = "ShiftB";
        public static string ShiftCodeC = "ShiftC";
        public static string ShiftCodeZ = "ShiftZ";

        public static DataTable DtLineInfo1 = null;
        public static DataTable DtLineInfo2 = null;
        public static DataTable DtLineInfo3 = null;

        public static DataTable DtLineShift1 = null;
        public static DataTable DtLineShift2 = null;
        public static DataTable DtLineShift3 = null;

        public static DataTable DtProductInfo1 = null;
        public static DataTable DtProductInfo2 = null;
        public static DataTable DtProductInfo3 = null;

        /// <summary>
        /// Init Config Info
        /// </summary>
        public static void InitConfigInfo()
        {
            if (string.Equals("T", ConfigurationManager.AppSettings["IsUseCustomizedFont"].ToString().Trim().ToUpper()))
            {
                IsUseCustomizedFont = true;
            }
            else
            {
                IsUseCustomizedFont = false;
            }

            float tempSize = 0F;

            if (float.TryParse(ConfigurationManager.AppSettings["FontSizeTitle"].ToString().Trim(), out tempSize))
            {
                FontSizeTitle = tempSize;
            }

            if (float.TryParse(ConfigurationManager.AppSettings["FontSizeCaption"].ToString().Trim(), out tempSize))
            {
                FontSizeCaption = tempSize;
            }

            if (float.TryParse(ConfigurationManager.AppSettings["FontSizeValue"].ToString().Trim(), out tempSize))
            {
                FontSizeValue = tempSize;
            }

            if (float.TryParse(ConfigurationManager.AppSettings["FontSizeScreenSaver"].ToString().Trim(), out tempSize))
            {
                FontSizeScreenSaver = tempSize;
            }

            if (string.Equals("T", ConfigurationManager.AppSettings["IsProductPC"].ToString().Trim().ToUpper()))
            {
                IsProductPC = true;
            }
            else
            {
                IsProductPC = false;
            }

            WatchLines = ConfigurationManager.AppSettings["WatchLines"].ToString().Trim();

            if (string.Equals("T", ConfigurationManager.AppSettings["IsUseScreenSaver"].ToString().Trim().ToUpper()))
            {
                IsUseScreenSaver = true;
            }
            else
            {
                IsUseScreenSaver = false;
            }

            int temp = 0;

            if (int.TryParse(ConfigurationManager.AppSettings["ShowScreenSaverSpan"].ToString().Trim(), out temp))
            {
                ShowScreenSaverSpan = temp;
            }

            if (int.TryParse(ConfigurationManager.AppSettings["RefreshSaverSpan"].ToString().Trim(), out temp))
            {
                RefreshSaverSpan = temp;
            }

            if (string.Equals("T", ConfigurationManager.AppSettings["IsDemoTimerEnable"].ToString().Trim().ToUpper()))
            {
                IsDemoTimerEnable = true;
            }
            else
            {
                IsDemoTimerEnable = false;
            }

            if (int.TryParse(ConfigurationManager.AppSettings["UpdateDemoProductInfoSpan"].ToString().Trim(), out temp))
            {
                UpdateDemoProductInfoSpan = temp;
            }

            if (int.TryParse(ConfigurationManager.AppSettings["RefreshLineInfoSpan"].ToString().Trim(), out temp))
            {
                RefreshLineInfoSpan = temp;
            }

            if (int.TryParse(ConfigurationManager.AppSettings["RefreshProductInfoSpan"].ToString().Trim(), out temp))
            {
                RefreshProductInfoSpan = temp;
            }
        }

        /// <summary>
        /// Get Now Plan Info
        /// </summary>
        /// <param name="lineWatchSys"></param>
        /// <param name="planNum"></param>
        /// <returns></returns>
        public static long GetNowPlanInfo(DataTable lineShift, long planNum)
        {
            long nowPlanNum = 0;

            DateTime shiftAStartTime = ConfigInfo.GetShitAStartTime(lineShift);
            DateTime shiftAEndTime = ConfigInfo.GetShitAEndTime(lineShift);
            long shiftARestTime = GetShitARestTime(lineShift);

            DateTime shiftBStartTime = ConfigInfo.GetShitBStartTime(lineShift);
            DateTime shiftBEndTime = ConfigInfo.GetShitBEndTime(lineShift);
            long shiftBRestTime = GetShitBRestTime(lineShift);

            DateTime shiftCStartTime = ConfigInfo.GetShitCStartTime(lineShift);
            DateTime shiftCEndTime = ConfigInfo.GetShitCEndTime(lineShift);
            long shiftCRestTime = GetShitCRestTime(lineShift);

            DateTime currentTime = DateTime.Now;

            string shift = ConfigInfo.GetShift(lineShift);

            if (string.Equals(shift, ConfigInfo.ShiftCodeA))
            {
                // 班次：1班
                double timeSpanTotal = (shiftAEndTime - shiftAStartTime).TotalSeconds;
                double timeSpanNow = (currentTime - shiftAStartTime).TotalSeconds;
                double currentRestTime = shiftARestTime * (timeSpanNow / timeSpanTotal);
                string NowPlan=  ConfigurationManager.AppSettings["NowPlanA"].ToString();
                string NowPlanTime = ConfigurationManager.AppSettings["NowPlanTimeA"].ToString();
                double NowPlanLeave=(currentTime - DateTime.Parse(NowPlanTime)).TotalSeconds;
                double i = (timeSpanTotal - currentRestTime) / planNum;
                if (NowPlan!="0")
                {
                    if (NowPlanLeave >= (timeSpanTotal - currentRestTime) / planNum)
                    {
                        nowPlanNum = int.Parse(NowPlan) + 1;
                        ConfigurationManager.AppSettings["NowPlanA"] = nowPlanNum.ToString();
                        ConfigurationManager.AppSettings["NowPlanTimeA"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        //XmlDocument xmlDoc = new XmlDocument();
                        //xmlDoc.Load(ConfigurationManager.AppSettings["Directory"].ToString().Trim());
                        //XmlElement node1 = (XmlElement)xmlDoc.SelectSingleNode("//add[@key='NowPlanA']");
                        //node1.SetAttribute("value", nowPlanNum.ToString());
                        //XmlElement node2 = (XmlElement)xmlDoc.SelectSingleNode("//add[@key='NowPlanTimeA']");
                        //node2.SetAttribute("value", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        //xmlDoc.Save(ConfigurationManager.AppSettings["Directory"].ToString().Trim());
                    }
                    else
                    {
                        nowPlanNum = int.Parse(NowPlan);
                    }
                }
                else
                {
                    nowPlanNum = (long)(planNum * (timeSpanNow - currentRestTime) / (timeSpanTotal - currentRestTime));
                    ConfigurationManager.AppSettings["NowPlanA"] = nowPlanNum.ToString();
                    //XmlDocument xmlDoc = new XmlDocument();
                    //xmlDoc.Load(ConfigurationManager.AppSettings["Directory"].ToString().Trim());
                    //XmlElement node1 = (XmlElement)xmlDoc.SelectSingleNode("//add[@key='NowPlanA']");
                    //node1.SetAttribute("value", "0");
                    //XmlElement node2 = (XmlElement)xmlDoc.SelectSingleNode("//add[@key='NowPlanTimeA']");
                    //node2.SetAttribute("value", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    //xmlDoc.Save(ConfigurationManager.AppSettings["Directory"].ToString().Trim());
                }
            }
            else if (string.Equals(shift, ConfigInfo.ShiftCodeB))
            {
                // 班次：2班
                double timeSpanTotal = (shiftBEndTime - shiftBStartTime).TotalSeconds;
                double timeSpanNow = (currentTime - shiftBStartTime).TotalSeconds;
                double currentRestTime = shiftBRestTime * (timeSpanNow / timeSpanTotal);
                string NowPlan = ConfigurationManager.AppSettings["NowPlanB"].ToString();
                string NowPlanTime = ConfigurationManager.AppSettings["NowPlanTimeB"].ToString();
                double NowPlanLeave = (currentTime - DateTime.Parse(NowPlanTime)).TotalSeconds;
                if (NowPlan != "0")
                {
                    if (NowPlanLeave >= (timeSpanTotal - currentRestTime) / planNum)
                    {
                        nowPlanNum = int.Parse(NowPlan) + 1;
                        ConfigurationManager.AppSettings["NowPlanB"] = nowPlanNum.ToString();
                        ConfigurationManager.AppSettings["NowPlanTimeB"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        //XmlDocument xmlDoc = new XmlDocument();
                        //xmlDoc.Load(ConfigurationManager.AppSettings["Directory"].ToString().Trim());
                        //XmlElement node1 = (XmlElement)xmlDoc.SelectSingleNode("//add[@key='NowPlanB']");
                        //node1.SetAttribute("value", nowPlanNum.ToString());
                        //XmlElement node2 = (XmlElement)xmlDoc.SelectSingleNode("//add[@key='NowPlanTimeB']");
                        //node2.SetAttribute("value", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        //xmlDoc.Save(ConfigurationManager.AppSettings["Directory"].ToString().Trim());
                    }
                    else
                    {
                        nowPlanNum = int.Parse(NowPlan);
                    }
                }
                else
                {
                    nowPlanNum = (long)(planNum * (timeSpanNow - currentRestTime) / (timeSpanTotal - currentRestTime));
                    ConfigurationManager.AppSettings["NowPlanB"] = nowPlanNum.ToString();
                    //XmlDocument xmlDoc = new XmlDocument();
                    //xmlDoc.Load(ConfigurationManager.AppSettings["Directory"].ToString().Trim());
                    //XmlElement node1 = (XmlElement)xmlDoc.SelectSingleNode("//add[@key='NowPlanB']");
                    //node1.SetAttribute("value", "0");
                    //XmlElement node2 = (XmlElement)xmlDoc.SelectSingleNode("//add[@key='NowPlanTimeB']");
                    //node2.SetAttribute("value", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    //xmlDoc.Save(ConfigurationManager.AppSettings["Directory"].ToString().Trim());
                }
            }
            else if (string.Equals(shift, ConfigInfo.ShiftCodeC))
            {
                // 班次：3班
                double timeSpanTotal = (shiftCEndTime - shiftCStartTime).TotalSeconds;
                double timeSpanNow = (currentTime - shiftCStartTime).TotalSeconds;
                double currentRestTime = shiftCRestTime * (timeSpanNow / timeSpanTotal);
                string NowPlan = ConfigurationManager.AppSettings["NowPlanC"].ToString();
                string NowPlanTime = ConfigurationManager.AppSettings["NowPlanTimeC"].ToString();
                double NowPlanLeave = (currentTime - DateTime.Parse(NowPlanTime)).TotalSeconds;
                if (NowPlan != "0")
                {
                    if (NowPlanLeave >= (timeSpanTotal - currentRestTime) / planNum)
                    {
                        nowPlanNum = int.Parse(NowPlan) + 1;
                        ConfigurationManager.AppSettings["NowPlanC"] = nowPlanNum.ToString();
                        ConfigurationManager.AppSettings["NowPlanTimeC"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        //XmlDocument xmlDoc = new XmlDocument();
                        //xmlDoc.Load(ConfigurationManager.AppSettings["Directory"].ToString().Trim());
                        //XmlElement node1 = (XmlElement)xmlDoc.SelectSingleNode("//add[@key='NowPlanC']");
                        //node1.SetAttribute("value", nowPlanNum.ToString());
                        //XmlElement node2 = (XmlElement)xmlDoc.SelectSingleNode("//add[@key='NowPlanTimeC']");
                        //node2.SetAttribute("value", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        //xmlDoc.Save(ConfigurationManager.AppSettings["Directory"].ToString().Trim());
                    }
                    else
                    {
                        nowPlanNum = int.Parse(NowPlan);
                    }
                }
                else
                {
                    nowPlanNum = (long)(planNum * (timeSpanNow - currentRestTime) / (timeSpanTotal - currentRestTime));
                    ConfigurationManager.AppSettings["NowPlanC"] = nowPlanNum.ToString();
                    //XmlDocument xmlDoc = new XmlDocument();
                    //xmlDoc.Load(ConfigurationManager.AppSettings["Directory"].ToString().Trim());
                    //XmlElement node1 = (XmlElement)xmlDoc.SelectSingleNode("//add[@key='NowPlanC']");
                    //node1.SetAttribute("value", "0");
                    //XmlElement node2 = (XmlElement)xmlDoc.SelectSingleNode("//add[@key='NowPlanTimeC']");
                    //node2.SetAttribute("value", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    //xmlDoc.Save(ConfigurationManager.AppSettings["Directory"].ToString().Trim());
                }
            }

            if (nowPlanNum < 0)
            {
                nowPlanNum = 0;
            }

            if (nowPlanNum > planNum)
            {
                nowPlanNum = planNum;
            }

            return nowPlanNum;
        }

        /// <summary>
        /// Get Shift Info
        /// </summary>
        /// <param name="lineWatchSys"></param>
        /// <returns></returns>
        public static string GetShiftInfo(DataTable lineShift)
        {
            string shiftInfo = string.Empty;
            string shift = ConfigInfo.GetShift(lineShift);

            if (string.Equals(shift, ConfigInfo.ShiftCodeA))
            {
                shiftInfo = "班组：1班";
            }
            else if (string.Equals(shift, ConfigInfo.ShiftCodeB))
            {
                shiftInfo = "班组：2班";
            }
            else if (string.Equals(shift, ConfigInfo.ShiftCodeC))
            {
                shiftInfo = "班组：3班";
            }
            else
            {
                shiftInfo = "班组：未知";
            }

            return shiftInfo;
        }

        /// <summary>
        /// Get Shift Plan Num
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static long GetShiftPlanNum(DataTable lineShift, string NumTime)
        {
            string shift = ConfigInfo.GetShift(lineShift);
            string planNumTemp = string.Empty;
            long planNum = 0;

            foreach (DataRow row in lineShift.Rows)
            {
                if (string.Equals(shift, row["Shift"].ToString().Trim()) && string.Equals(NumTime, row["NumTime"].ToString().Trim()))
                {
                    planNumTemp = row["PlanNum"].ToString().Trim();
                    long.TryParse(planNumTemp, out planNum);
                    break;
                }
            }

            return planNum;
        }

        /// <summary>
        /// Get Shift Product Num
        /// </summary>
        /// <param name="lineShift"></param>
        /// <param name="productInfo"></param>
        /// <returns></returns>
        public static long GetShiftProductNum(string shift, DataTable productInfo)
        {
            string productNumTemp = string.Empty;
            long productNum = 0;

            foreach (DataRow row in productInfo.Rows)
            {
                if (string.Equals(shift, row["Shift"].ToString().Trim()))
                {
                    productNumTemp = row["ProductNum"].ToString().Trim();
                    long.TryParse(productNumTemp, out productNum);
                    break;
                }
            }

            return productNum;
        }

        /// <summary>
        /// Get Shift
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static string GetShift(DataTable lineShift)
        {
            string shift = string.Empty;
            DateTime shiftAStartTime = ConfigInfo.GetShitAStartTime(lineShift);
            DateTime shiftAEndTime = ConfigInfo.GetShitAEndTime(lineShift);
            DateTime shiftBStartTime = ConfigInfo.GetShitBStartTime(lineShift);
            DateTime shiftBEndTime = ConfigInfo.GetShitBEndTime(lineShift);
            DateTime shiftCStartTime = ConfigInfo.GetShitCStartTime(lineShift);
            DateTime shiftCEndTime = ConfigInfo.GetShitCEndTime(lineShift);
            DateTime currentTime = ConfigInfo.GetCurrentTime();

            if ((currentTime >= shiftAStartTime)
                && (currentTime <= shiftAEndTime))
            {
                shift = ConfigInfo.ShiftCodeA;
            }
            else if ((currentTime >= shiftBStartTime)
                && (currentTime <= shiftBEndTime))
            {
                shift = ConfigInfo.ShiftCodeB;
            }
            else if ((currentTime >= shiftCStartTime)
                && (currentTime <= shiftCEndTime))
            {
                shift = ConfigInfo.ShiftCodeC;
            }
            else
            {
                shift = ConfigInfo.ShiftCodeZ;
            }

            return shift;
        }

        /// <summary>
        /// Get Current Work Date
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static DateTime GetCurrentWorkDate(DataTable lineShift)
        {
            string currentWorkDate = string.Empty;
            DateTime shiftAStartTime = ConfigInfo.GetWorkDayStartTime(lineShift);

            DateTime currentTime = ConfigInfo.GetCurrentTime();

            if (currentTime >= shiftAStartTime)
            {
                currentWorkDate = currentTime.ToString("yyyy-MM-dd");
            }
            else
            {
                currentWorkDate = currentTime.AddDays(-1).ToString("yyyy-MM-dd");
            }

            return DateTime.Parse(currentWorkDate);
        }

        /// <summary>
        /// Get Work Day Start Time
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static DateTime GetWorkDayStartTime(DataTable lineShift)
        {
            string strTime = "00:00";

            foreach (DataRow row in lineShift.Rows)
            {
                if (string.Equals("ShiftA", row["Shift"].ToString().Trim()))
                {
                    strTime = row["StartTime"].ToString().Trim();
                    break;
                }
            }

            string today = DateTime.Today.ToString("yyyy-MM-dd");
            string dayAndTime = today + " " + strTime + ":00";
            DateTime dateTime = DateTime.Parse(strTime);

            return dateTime;
        }

        /// <summary>
        /// Get ShitA Start Time
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static DateTime GetShitAStartTime(DataTable lineShift)
        {
            string strTime = "00:00";

            foreach (DataRow row in lineShift.Rows)
            {
                if (string.Equals("ShiftA", row["Shift"].ToString().Trim()))
                {
                    strTime = row["StartTime"].ToString().Trim();
                    break;
                }
            }

            string today = GetCurrentWorkDate(lineShift).ToString("yyyy-MM-dd");
            string dayAndTime = today + " " + strTime + ":00";
            DateTime dateTime = DateTime.Parse(strTime);

            return dateTime;
        }

        /// <summary>
        /// Get ShitA End Time
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static DateTime GetShitAEndTime(DataTable lineShift)
        {
            string strTime = "00:00";

            foreach (DataRow row in lineShift.Rows)
            {
                if (string.Equals("ShiftA", row["Shift"].ToString().Trim()))
                {
                    strTime = row["EndTime"].ToString().Trim();
                    break;
                }
            }

            string today = GetCurrentWorkDate(lineShift).ToString("yyyy-MM-dd");
            string dayAndTime = today + " " + strTime + ":59";
            DateTime dateTime = DateTime.Parse(strTime);

            //DateTime shiftAStartTime = ConfigInfo.GetShitAStartTime(lineShift);

            //if (dateTime <= shiftAStartTime)
            //{
            //    dateTime = dateTime.AddDays(1);
            //}

            return dateTime;
        }

        /// <summary>
        /// Get ShitA Rest Time
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static long GetShitARestTime(DataTable lineShift)
        {
            long restTime = 0;
            string strTime = string.Empty;

            foreach (DataRow row in lineShift.Rows)
            {
                if (string.Equals("ShiftA", row["Shift"].ToString().Trim()))
                {
                    strTime = row["RestTime"].ToString().Trim();
                    break;
                }
            }

            long.TryParse(strTime, out restTime);

            return restTime;
        }

        /// <summary>
        /// Get ShitB Start Time
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static DateTime GetShitBStartTime(DataTable lineShift)
        {
            string strTime = "00:00";

            foreach (DataRow row in lineShift.Rows)
            {
                if (string.Equals("ShiftB", row["Shift"].ToString().Trim()))
                {
                    strTime = row["StartTime"].ToString().Trim();
                    break;
                }
            }

            string today = GetCurrentWorkDate(lineShift).ToString("yyyy-MM-dd");
            string dayAndTime = today + " " + strTime + ":00";
            DateTime dateTime = DateTime.Parse(strTime);

            return dateTime;
        }

        /// <summary>
        /// Get ShitB End Time
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static DateTime GetShitBEndTime(DataTable lineShift)
        {
            string strTime = "00:00";

            foreach (DataRow row in lineShift.Rows)
            {
                if (string.Equals("ShiftB", row["Shift"].ToString().Trim()))
                {
                    strTime = row["EndTime"].ToString().Trim();
                    break;
                }
            }

            string today = GetCurrentWorkDate(lineShift).ToString("yyyy-MM-dd");
            string dayAndTime = today + " " + strTime + ":59";
            DateTime dateTime = DateTime.Parse(strTime);

            //DateTime shiftBStartTime = ConfigInfo.GetShitBStartTime(lineShift);

            //if (dateTime <= shiftBStartTime)
            //{
            //    dateTime = dateTime.AddDays(1);
            //}

            return dateTime;
        }

        /// <summary>
        /// Get ShitB Rest Time
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static long GetShitBRestTime(DataTable lineShift)
        {
            long restTime = 0;
            string strTime = string.Empty;

            foreach (DataRow row in lineShift.Rows)
            {
                if (string.Equals("ShiftB", row["Shift"].ToString().Trim()))
                {
                    strTime = row["RestTime"].ToString().Trim();
                    break;
                }
            }

            long.TryParse(strTime, out restTime);

            return restTime;
        }

        /// <summary>
        /// Get ShitC Start Time
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static DateTime GetShitCStartTime(DataTable lineShift)
        {
            string strTime = "00:00";

            foreach (DataRow row in lineShift.Rows)
            {
                if (string.Equals("ShiftC", row["Shift"].ToString().Trim()))
                {
                    strTime = row["StartTime"].ToString().Trim();
                    break;
                }
            }

            string today = GetCurrentWorkDate(lineShift).ToString("yyyy-MM-dd");
            string dayAndTime = today + " " + strTime + ":00";
            DateTime dateTime = DateTime.Parse(strTime);

            return dateTime;
        }

        /// <summary>
        /// Get ShitC End Time
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static DateTime GetShitCEndTime(DataTable lineShift)
        {
            string strTime = "00:00";

            foreach (DataRow row in lineShift.Rows)
            {
                if (string.Equals("ShiftC", row["Shift"].ToString().Trim()))
                {
                    strTime = row["EndTime"].ToString().Trim();
                    break;
                }
            }

            string today = GetCurrentWorkDate(lineShift).ToString("yyyy-MM-dd");
            string dayAndTime = today + " " + strTime + ":59";
            DateTime dateTime = DateTime.Parse(strTime);

            //DateTime shiftCStartTime = ConfigInfo.GetShitCStartTime(lineShift);

            //if (dateTime <= shiftCStartTime)
            //{
            //    dateTime = dateTime.AddDays(1);
            //}

            return dateTime;
        }

        /// <summary>
        /// Get ShitC Rest Time
        /// </summary>
        /// <param name="lineShift"></param>
        /// <returns></returns>
        public static long GetShitCRestTime(DataTable lineShift)
        {
            long restTime = 0;
            string strTime = string.Empty;

            foreach (DataRow row in lineShift.Rows)
            {
                if (string.Equals("ShiftC", row["Shift"].ToString().Trim()))
                {
                    strTime = row["RestTime"].ToString().Trim();
                    break;
                }
            }

            long.TryParse(strTime, out restTime);

            return restTime;
        }

        /// <summary>
        /// Get Current Time
        /// </summary>
        /// <returns></returns>
        public static DateTime GetCurrentTime()
        {
            string currentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            return DateTime.Parse(currentTime);
        }
    }
}
